/*
 * Powered By fanrenqij.com
 * Since 2017 - 2017
 */

package com.fanrenqiji.modules.business.parentdailyscore.web;


import com.fanrenqiji.common.config.GlobalSetting;
import com.fanrenqiji.common.persistence.Page;
import com.fanrenqiji.common.web.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import com.fanrenqiji.modules.business.parentdailyscore.vo.ParentDailyScoreVO;
import com.fanrenqiji.modules.business.parentdailyscore.service.ParentDailyScoreService;

@Controller
@RequestMapping(value = "${adminPath}/business/parentdailyscore")
public class ParentDailyScoreController extends BaseController {
	
    private static Logger log = LoggerFactory.getLogger(ParentDailyScoreController.class);
    @Autowired
	private ParentDailyScoreService parentDailyScoreService;

@ModelAttribute("parentDailyScore")
public ParentDailyScoreVO getParentDailyScore(@RequestParam(required = false) String id){
	if(StringUtils.isNotEmpty(id)){
		return parentDailyScoreService.get(id);
	}else{
		return new ParentDailyScoreVO();
	}
}

/**
 * 列表
 *
 * @return
 */
@RequiresPermissions("business:parentdailyscore:view")
@RequestMapping(value = {"list", ""})
public String list(ParentDailyScoreVO parentDailyScore,HttpServletRequest request,
		HttpServletResponse response,Model model){
	Page<ParentDailyScoreVO> page = parentDailyScoreService.findParentDailyScoreByPage(new Page<ParentDailyScoreVO>(request,response),
		parentDailyScore);
	model.addAttribute("page",page);
	model.addAttribute("parentDailyScore",parentDailyScore);
	return"modules/business/parentdailyscore/parentdailyscoreList";
}

/**
 * 选择列表
 *
 * @return
 */
@RequestMapping(value = "select")
public String select(ParentDailyScoreVO parentDailyScore,HttpServletRequest request,HttpServletResponse response,Model model){
	Page<ParentDailyScoreVO> page = parentDailyScoreService.findParentDailyScoreByPage(new Page<ParentDailyScoreVO>(request,response,10),parentDailyScore);
	model.addAttribute("page",page);
	model.addAttribute("parentDailyScore",parentDailyScore);
	return"modules/business/parentdailyscore/parentdailyscoreSelect";
}

/**
 * 用户添加更新表
 *
 * @param model
 * @return
 */
@RequiresPermissions("business:parentdailyscore:view")
@RequestMapping(value = "form")
public String form(Model model,ParentDailyScoreVO parentDailyScore){
	if (StringUtils.isNotEmpty(parentDailyScore.getId())) {
		model.addAttribute("parentDailyScore", parentDailyScoreService.get(parentDailyScore.getId()));
	}else{
		model.addAttribute("parentDailyScore",parentDailyScore);
	}
	return"modules/business/parentdailyscore/parentdailyscoreForm";
}

/**
 * 添加或修改提交
 *
 * @param parentDailyScore
 * @param model
 * @param redirectAttributes
 * @return
 */
@RequiresPermissions("business:parentdailyscore:edit")
@RequestMapping(value = "save")
public String save(ParentDailyScoreVO parentDailyScore,Model model,
		RedirectAttributes redirectAttributes){// TODO @Valid 添加后端校验
	if(!beanValidator(model,parentDailyScore)){
		return form(model,parentDailyScore);
	}
	parentDailyScoreService.update(parentDailyScore);
	addMessage(redirectAttributes,"保存成功");
	return"redirect:"+GlobalSetting.getAdminPath()
		+"/business/parentdailyscore/?repage";
}

/**
 * 删除操作
 *
 * @return
 */
@RequestMapping("delete")
@RequiresPermissions("business:parentdailyscore:edit")
public String delete(String id, RedirectAttributes redirectAttributes) {
	parentDailyScoreService.delete(id);
	addMessage(redirectAttributes, "删除成功");
	return "redirect:" + GlobalSetting.getAdminPath() + "/business/parentdailyscore/";
}
}